﻿using Goooodbye.Presentation.WinFormsApp.Properties;
using System;
using System.Text.RegularExpressions;

namespace Goooodbye.Presentation.WinFormsApp
{
    public partial class FormSettings : FormBase
    {
        public FormSettings()
        {
            InitializeComponent();
        }

        private void FormSettings_Load(object sender, EventArgs e)
        {
            this.comboLang.DataSource = Settings.Default.Languages;
            foreach (var item in Settings.Default.Languages)
            {
                if (item.Contains(Settings.Default.Lang))
                {
                    this.comboLang.Text = item;
                    break;
                }
            }
            this.numPageSize.Value = Settings.Default.PageSize;
            this.radioCSV.Checked = Settings.Default.DefaultExt == "csv";
            this.radioTXT.Checked = !this.radioCSV.Checked;
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            Settings.Default.Lang = Regex.Match(this.comboLang.Text, @"(?<=\().+(?=\))").Value;           
            Settings.Default.PageSize = (int)this.numPageSize.Value;
            Settings.Default.DefaultExt = this.radioCSV.Checked ? "csv" : "txt";
            Settings.Default.Save();
        }
    }
}
